/**
 * @author        Nicolas Bottarini <nicolasbottarini@gmail.com>, 404 <http://www.proyecto404.com>
 * @version       $Rev: 3 $
 * @lastrevision  $Date: 2011-09-12 16:45:37 +0000 (Mon, 12 Sep 2011) $	 
 */
package com.proyecto404.core.mvc {
	import com.proyecto404.core.exception.AbstractMethodException;
	import com.proyecto404.core.io.MultiFileLoadProgressEventArgs;

	/**
	 * @abstract
	 */ 
	public class PreloaderView extends View {
		private var _preloader:Preloader;
		
		public function PreloaderView() {
			super();
		}
		
		protected override function onInit():void {
			_preloader = model as Preloader;
			_preloader.progress.add(onLoaderProgress);			
		}
		
		/**
		 * @abstract
		 */ 
		protected function showProgress(partialProgress:Number, loadedFiles:int, totalFiles:int, totalProgress:Number):void {
			throw new AbstractMethodException();
		}
		
		private function onLoaderProgress(e:MultiFileLoadProgressEventArgs):void {
			var partialProgress:Number = (e.bytesLoaded / e.bytesTotal);
			var totalProgress:Number = ((e.fileNumber - 1 + partialProgress)/ e.totalFiles); 
			showProgress(e.bytesLoaded / e.bytesTotal, e.fileNumber, e.totalFiles, totalProgress);	
		}
	}
}